package com.spring.springbootmodel.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 作者：黄龙华
 * 功能：拦截器配置
 * 日期：2023/11/12 16:35
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())   //配置jwt的拦截器规则
                .addPathPatterns("/**")   //拦截所有的请求路径
                .excludePathPatterns("/**/login");     //放行登录界面，登录界面不需要验证也没有登录
        super.addInterceptors(registry);
    }

    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }
}